﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Xml;
using DataAccess;
using ClickReadService.Models;

namespace ClickReadService
{
  // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
  public class ClickRead : IClickRead
  {
    Repository repository = new Repository();

    public SinglePage GetPage(int bookID, int pageID)
    {
      var page = this.repository.Get<Page>(p => p.BookID == bookID && p.PageID == pageID);
      return new SinglePage()
      {
        Image = page.Image,
        pageID = page.PageID,
        Spots = this.repository
         .Where<Spot>(s => s.BookID == page.BookID && s.PageID == page.PageID)
         .Select(s => new HotArea()
         {
           HotAreaID = s.SpotID,
           Coords = s.Coords,
           Shape = s.Shape,
           Sound = s.Sound,
           Alt = s.Alt,
           Words = s.Words,
           Symbol = s.Symbols,
           Meaning = s.Meaning,
           TypeID = s.TypeID
         }).ToList()
      };
    }

    public List<SingleBook> GetBooks()
    {
      return this.repository.db.Books.Select(b =>
        new SingleBook()
        {
          BookID = b.BookID,
          Name = b.Name,
          Album=b.Album,
          Image=b.Image,
          Press=b.Press,
          PageCount=b.PageCount
        }).ToList();
    }
  }
}
